<?php //use_helper('Form') ?>
<?php use_javascript('/js/e-dsl/datepicker.js') ?>
<?php use_javascript('/js/json_parse.js') ?>
<?php use_stylesheet('/css/e-dsl/datepicker.css') ?>
<?php $objDef = new objectDef('demandes');?>
<?php include_partial('jsSelectTypeDemande', array('form' => $form, 'objDef' => $objDef)) ?>

<form id = "myForm" action="<?php print url_for('demandes/submitRecycle?id_demande_recycler='.$id_demande_recycler); ?>" method="post" enctype="multipart/form-data"  style="margin: 0; padding: 0;">
<?php //$form = new selTypeDemandeForm;?>
	<fieldset>
		<legend><?php echo __('Process transformation') ?></legend>
			<h1><?php echo __('This action will close the process %number% and create a new one', array('%number%' => $id_demande_recycler))?></h1>
			<div id="errorDisplayHaut" class="errorDisplay">&nbsp;</div>
			<fieldset>
				<legend><?php echo __('Process Selection')?></legend>
					<?php echo $objDef->renderAttributeWidget($form, 'domaine'); ?>
					<?php echo $form['typePere']->renderRow() ?>
					<?php echo $objDef->renderAttributeWidget($form, 'type_id'); ?>
					<?php echo $objDef->renderAttributeWidget($form, 'categorie_id'); ?>
					<?php include_partial('demandes/demandeDateFields', array('form' => $form, 'objDef' => $objDef)) ?>
					<?php  if ($form->isCSRFProtected()) : ?> 
						<?php echo $form['_csrf_token']; ?> 
					<?php endif; ?>
			</fieldset>
			<div class="buttons">
				<?php //if(!isset($_SESSION['f_dmdGroupee'])) echo link_to( '<img title="Retour" src="/images/formulaires/retour.png"></img>', 'demandes/demandesPhase1' )?>
				<?php echo link_to( '<img title="Cancel" src="/images/formulaires/annuler.png"></img>', 'demandes/anuler' )?>
				<input name="Submit" title="<?php echo __('Apply')?>" type="image" src="/images/formulaires/valider.png">
			</div>
	</fieldset>
</form>

<script type="text/javascript">
	$(document).ready(function(){    
		if(document.getElementById("demandes1_domaine_id").value)
		{
			refreshCandidatesType();
		}
	});

	function customVal(validators)
	{
		if(document.getElementById("demandes1_dateRealSouhaitee")){
			if (!verifdt(document.getElementById("demandes1_dateRealSouhaitee").value))
			{
				validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes1_dateRealSouhaitee")));	
			}
			else
			{
				var xDateSouhaitee = document.getElementById('demandes1_dateRealSouhaitee');
				dDateSouhaitee = getFieldDate(xDateSouhaitee.value);
				var currentDate = new Date();

				if(currentDate >= dDateSouhaitee)
				{
					x = validators.length;
					validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes1_dateRealSouhaitee")));
					validators[x].message = "La date souhait\351e est anterieur a la date de la demande.";
				}	 
			}
		}	
		
		if(document.getElementById("demandes1_justifurgence")){
			if(document.getElementById('demandes1_urgent').value == 'true')
			{
				if(ltrim(document.getElementById("demandes1_justifurgence").value)=="")
				{
					validators.push(tmt.validator.fieldValidatorFactory(document.getElementById("demandes1_justifurgence")));
				}
			}
		}
	}
</script>